01 / 04

How does Go implement interfaces differently from Java or C#?

Go uses implicit (structural) interface satisfaction — a type implements an interface simply by having the required methods, with no explicit declaration or 'implements' keyword.

Implicit interface satisfaction
Benefits over explicit interfaces (Java and C#)
  1. 1

    Decoupling: the consumer defines the interface — the library doesn't need to know about it

  2. 2

    No circular import issues caused by interface packages

  3. 3

    Third-party types can satisfy your interfaces without modification

  4. 4

    Interfaces are checked at compile time — no runtime casting overhead

  5. 5

    Enables the consumer-defined interface pattern: small, focused interfaces defined where they are used

Difficulty: 6/10
Topics: structural typing, method sets, nil interface handling

Scenario Questions

0-2 years experience
  1. 1

    Suppose you need to write a function that accepts any type that can be printed. How would you define the parameter using Go interfaces, and how does that differ from how you'd do it in Java?

  2. 2

    If you have a struct that implements a method with a pointer receiver, can a value of that struct be assigned to a variable of an interface type? Explain what happens and why it's different from C#.

2-5 years experience
  1. 1

    You added a new method to an existing interface in a Go codebase, and a type that previously satisfied the interface now fails to compile. Why did this happen, and how would you debug it compared to a similar change in Java?

  2. 2

    During a refactor, you notice that a function returning an interface value sometimes holds a nil underlying concrete value, causing a panic when you call a method. Explain why this occurs in Go and how it differs from null handling in Java/C#.

5-8 years experience
  1. 1

    Design a plugin architecture where plugins are loaded at runtime. Would you choose Go interfaces or Java's reflection‑based interfaces, and what are the trade‑offs in terms of type safety, performance, and binary size?

  2. 2

    Your microservice written in Go needs to expose a gRPC API that mirrors an existing Java service using interface definitions. How would you map Go's implicit interface implementation to the explicit contracts in Java, and what pitfalls should you watch for?

8+ years experience
  1. 1

    Your organization is migrating a large codebase from Java to Go. One concern is how interface contracts are enforced. How would you set up a migration strategy that ensures behavioral compatibility given Go's structural typing versus Java's nominal typing?

  2. 2

    Across multiple teams, you need to standardize how errors are propagated through interface methods. Discuss how Go's interface implementation model influences error handling design compared to Java/C#, and propose guidelines to avoid subtle bugs at scale.

Follow-up Questions

  • Can you give an example where Go's implicit implementation caused a surprising bug?
  • How do pointer vs value receivers affect whether a type satisfies an interface?
  • What are the implications for testing and mocking when interfaces are satisfied implicitly?